const nav = Pager.nav

function onCovering() {
  const pageshead = $$('#pageshead')
  pageshead.removeClass('activeSwitch')
}

export const routerMenu = ui_tree({
  $$id: 'admin',
  data: [
    {title: '订单', itemClass: 'menu-caption', idf: 'order'},
    {title: '列表', itemClass: 'item-icon icon-saui', attr: {file: '/order/list'}, parent: 'order'}, 
    {title: '表单', itemClass: 'item-icon icon-saui', attr: {file: '/order/detail'}, parent: 'order'}, 
  ],
  itemMethod: {
    aim(e, param, inst){
      let file = inst.attr('file')
      let parent = inst.parent().parent()
      if (parent) {
        parent.forEach(child=>{
          if (child && child.children) {
            child.children.forEach(son=>{
              son.removeClass('active')
            })
          }
        })
        inst.addClass('active')
        if (file) {
          setTimeout(() => {
            nav.redirectTo({
              url: file,
              beforeNav(to, from, next) {
                next()
              }
            })
          }, 50);
        }
      }
      onCovering()
    }
  },
  listClass: 'router-menu-list router-menus flex-column justify-between',
})